package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.StockOutcomeBill;
import cn.wolfcode.crm.query.StockOutcomeBillQueryObejct;
import cn.wolfcode.crm.service.IStockOutcomeBilService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/stockoutcome")
public class StockoutcomeController {

    @Autowired
    private IStockOutcomeBilService stockOutcomeBilService;

    @RequestMapping("")
    public String view() {
        return "stockoutcome/stockoutcomebill";
    }

    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(@ModelAttribute("qo") StockOutcomeBillQueryObejct qo) {

        PageResult result = stockOutcomeBilService.query(qo);
        return result;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        JsonResult result = new JsonResult();
        try {

            stockOutcomeBilService.deleteByPrimaryKey(id);
        } catch (Exception e) {
            e.printStackTrace();
            result.setMsg("删除失败");
        }
        return result;
    }


    @RequestMapping("/save")
    @ResponseBody
    public JsonResult save(StockOutcomeBill stockOutcomeBill,String info) {
        JsonResult result = new JsonResult();
        try {

            stockOutcomeBilService.insert(stockOutcomeBill,info);
        } catch (Exception e) {
            e.printStackTrace();
            result.setMsg("删除失败");
        }
        return result;
    }


    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(StockOutcomeBill stockOutcomeBill){
        JsonResult jsonResult = new JsonResult();
        try {
            stockOutcomeBilService.updateByPrimaryKey(stockOutcomeBill);
        } catch (Exception e) {
            jsonResult.setMsg("更新失败");
            e.printStackTrace();
        }
        return jsonResult;
    }













}
